package com.codingman.springmvcdemo2;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HelloController {
	@RequestMapping("/hello1")
	public String display1(HttpServletRequest req, ModelMap model) {

		// read the provided form data
		String name = req.getParameter("name");
		String pass = req.getParameter("pass");
		
		System.out.println("hello1 " + name + " " + pass);
		
		if (pass.equals("admin")) {
			String msg = "Hello " + name;
			// add a message to the model
			model.addAttribute("message", msg);
			return "view";
		} else {
			String msg = "Sorry " + name + ". You entered an incorrect password";
			model.addAttribute("message", msg);
			return "error";
		}
	}
	
	@RequestMapping("/hello2")
	public String display2(@RequestParam("name") String name, @RequestParam("pass") String pass, ModelMap model) {

		System.out.println("hello2 " + name + " " + pass);
		
		if (pass.equals("admin")) {
			String msg = "Hello " + name;
			// add a message to the model
			model.addAttribute("message", msg);
			return "view";
		} else {
			String msg = "Sorry " + name + ". You entered an incorrect password";
			model.addAttribute("message", msg);
			return "error";
		}
	}
}
